package com.pm.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.enums.BusinessType;
import com.pm.business.domain.PersonCertificate;
import com.pm.business.service.IPersonCertificateService;
import com.pm.common.utils.poi.ExcelUtil;
import com.pm.common.core.page.TableDataInfo;
import com.pm.system.service.ISysDictDataService;
import com.pm.common.core.domain.entity.SysDictData;

/**
 * 证书管理Controller
 * 
 * @author zxl
 * @date 2022-05-06
 */
@RestController
@RequestMapping("/business/person_certificate")
public class PersonCertificateController extends BaseController
{
    @Autowired
    private IPersonCertificateService personCertificateService;

    @Autowired
    private ISysDictDataService dictDataService;

    /**
     * 查询证书管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:person_certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonCertificate personCertificate)
    {
        startPage();
        List<PersonCertificate> list = personCertificateService.selectPersonCertificateList(personCertificate);
        return getDataTable(list);
    }

    /**
     * 导出证书管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:person_certificate:export')")
    @Log(title = "证书管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonCertificate personCertificate)
    {
        List<PersonCertificate> list = personCertificateService.selectPersonCertificateList(personCertificate);
        ExcelUtil<PersonCertificate> util = new ExcelUtil<PersonCertificate>(PersonCertificate.class);
        util.exportExcel(response, list, "证书管理数据");
    }

    /**
     * 获取证书管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:person_certificate:query')")
    @GetMapping(value = "/{certificateId}")
    public AjaxResult getInfo(@PathVariable("certificateId") Long certificateId)
    {
        return AjaxResult.success(personCertificateService.selectPersonCertificateByCertificateId(certificateId));
    }

    /**
     * 新增证书管理
     */
    @PreAuthorize("@ss.hasPermi('business:person_certificate:add')")
    @Log(title = "证书管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonCertificate personCertificate)
    {
        //added by gaojianhong for 将选取的字典值对应的名称赋值
        if (personCertificate.getCertificateDic()!=null && personCertificate.getCertificateDic()!="") {
            String certificateName = dictDataService.selectDictLabel("person_certificate_name",personCertificate.getCertificateDic());
            if (certificateName!=null){
                personCertificate.setCertificateName(certificateName);
            }
        }
        return toAjax(personCertificateService.insertPersonCertificate(personCertificate));
    }

    /**
     * 修改证书管理
     */
    @PreAuthorize("@ss.hasPermi('business:person_certificate:edit')")
    @Log(title = "证书管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonCertificate personCertificate)
    {
        //added by gaojianhong for 将选取的字典值对应的名称赋值
        if (personCertificate.getCertificateDic()!=null && personCertificate.getCertificateDic()!="") {
            String certificateName = dictDataService.selectDictLabel("person_certificate_name",personCertificate.getCertificateDic());
            if (certificateName!=null){
                personCertificate.setCertificateName(certificateName);
            }
        }
        return toAjax(personCertificateService.updatePersonCertificate(personCertificate));
    }

    /**
     * 删除证书管理
     */
    @PreAuthorize("@ss.hasPermi('business:person_certificate:remove')")
    @Log(title = "证书管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certificateIds}")
    public AjaxResult remove(@PathVariable Long[] certificateIds)
    {
        return toAjax(personCertificateService.deletePersonCertificateByCertificateIds(certificateIds));
    }
}
